#include <stdio.h>

typedef unsigned long NUM;
typedef unsigned long long BIG;

inline BIG reverse(BIG n)
{
	BIG r = 0;

	while (n)
	{
		r *= 10;
		r += n % 10;
		n /= 10;
	}

	return r;
}

inline bool is_palindrome(BIG n)
{
	return n == reverse(n);
}

int main()
{
	NUM result = 0, i, j;

	for (i = 1; i < 10000; i++)
	{
		BIG n = i, reversed = reverse(n);

		for (j = 0; j < 50; j++)
		{
			n += reversed;
        	reversed = reverse(n);

			if (n == reversed)
				break;
		}

		if (j == 50)
			result++;

	}

	printf("%lu", result); // 249

	return 0;
}

